<?php
declare (strict_types=1);

namespace app\common\customer\model;

use app\common\config\logic\DictionaryLogic;
use app\common\config\logic\SourceLogic;
use app\common\system\logic\UserLogic;
use think\Model;
use think\model\concern\SoftDelete;


class OperateCost extends Model
{
    protected $table = "tk_operate_cost";
    
    use SoftDelete;
    protected $defaultSoftDelete = 0;

    protected $type = [
        'cost_date' => 'timestamp',
    ];

    public function getBrandAttr($value, $data)
    {
        if (empty($data['brand_id'])) {
            return [
                "id" => '',
                "title" => ''
            ];
        }

        $logic = new DictionaryLogic();
        return $logic->getItem($data['brand_id'], 'app\common\config\model\ConfigCompany', ['id', 'title']);
    }

    // 渠道的全路径
    public function getSourceAttr($value, $data)
    {
        if (empty($data['source_id'])) return '';
        $logic = new DictionaryLogic();

        return $logic->getFullPath($data['source_id']);
    }

    // 获取创建者对象
    public function getUserAttr($value, $data)
    {
        $logic = new UserLogic();
        return $logic->getUser($data['user_id'], ['id', 'realname', 'mobile', 'avatar']);
    }

}
